package com.hyt.it.ogt.ks.controller;


import java.util.List;

import javax.annotation.Resource;

import com.hyt.it.ogt.ks.enums.log.WebsocketMsgSendState;
import com.hyt.it.ogt.ks.exception.KsException;
import com.hyt.it.ogt.ks.service.IApplyCheckMsgService;
import com.hyt.it.ogt.ks.service.IApplyCheckService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import com.hyt.common.apiInfor.ApiResponse;
import com.hyt.it.ogt.ks.enums.BizStatusCode;
import com.hyt.it.ogt.ks.service.ICandidateLogOtherService;
import com.hyt.it.ogt.opertaion.track.model.OtherLogVO;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSort;
import lombok.extern.slf4j.Slf4j;

/**
 * <p>
 * 轨迹表-其他轨迹表 前端控制器
 * </p>
 *
 * @author liteng
 * @since 2022-11-22
 */
@RestController
@Slf4j
@RequestMapping("/ks/candidate-log-other")
@Api(tags = "56.轨迹接口")
public class CandidateLogOtherController {

    @Resource
    private ICandidateLogOtherService candidateLogOtherService;
    @Resource
    private IApplyCheckService applyCheckService;

    @PostMapping("/saveOtherLog")
    @ApiOperation(value = "保存其它轨迹日志", notes = "状态码：20000 成功 异常码：42130103 失败")
    @ApiOperationSort(1)
    public Object saveAnswerLog(@RequestBody List<OtherLogVO> otherLogVOList) {
        log.info("保存其它轨迹日志，收到参数为:【{}】,", otherLogVOList);
        try {
            return com.hyt.common.apiInfor.ApiResponse.builder()
                    .code(BizStatusCode.KS_SUCCESS_OK.getCode())
                    .data(candidateLogOtherService.saveOtherLog(otherLogVOList))
                    .build();
        } catch (Exception ex) {
            log.error("保存其它轨迹日志异常，收到参数为:【{}】,", otherLogVOList, ex);
            return ApiResponse.builder()
                    .code(BizStatusCode.SAVE_OTHER_LOG_FAIL.getCode())
                    .build();
        }
    }

    @ApiOperation(value = "56.2 考生查询设备检测审核结果 响应结果-1没有待审核记录 0-待审核 1-审核通过 2-审核不通过")
    @ApiOperationSort(2)
    @GetMapping("/deviceVerifyResult/{examId}/{candidateId}")
    public ApiResponse<Integer> deviceVerifyResult(@PathVariable String examId, @PathVariable String candidateId) {
        try {
            log.info("考生查询设备检测审核结果：{} {}", examId, candidateId);
            return ApiResponse.<Integer>builder()
                    .code(BizStatusCode.KS_SUCCESS_OK.getCode())
                    .data(applyCheckService.deviceVerifyResult(examId, candidateId))
                    .build();
        } catch (KsException e) {
            log.error("考生查询设备检测审核结果报业务错误：", e);
            return ApiResponse.<Integer>builder().code(e.getErrCode()).build();
        } catch (Exception e) {
            log.error("考生查询设备检测审核结果报内部错误：", e);
            return ApiResponse.<Integer>builder().code(BizStatusCode.CANDIDATE_OTHER_LOG_GET_DEVICE_VERIFY_RESULT_ERROR.getCode()).build();
        }
    }

}
